import logging
from cgitb import handler

#默认情况下，logging输出warning及以上级别的日志
#指定输出级别，输出info及以上级别的日志
logging.basicConfig(level=logging.INFO)

# logging.debug("this is a debug message")
# logging.info("this is a info message")
# logging.warning("this is a warning message")
# logging.error("this is a error message")
# logging.critical("this is a critical message")

logger = logging.getLogger("my_logger")
#给logger对象配置自己的日志 级别
logger.setLevel(level=logging.ERROR)

# 创建文件处理器---将日志输出到mylog.log(可以自动创建)
handler = logging.FileHandler(filename="mylog.log")

# 创建一个日志格式器对象
formatter = logging.Formatter(
    "%(asctime)s %(levelname)s [%(name)s] [%(filename)s (%(funcName)s:%(lineno)d)] - %(message)s"
)

# 将格式器设置到处理器上
handler.setFormatter(formatter)


# 将处理器添加到日志记录器中
logger.addHandler(handler)


logger.debug("this is a debug message")
logger.info("this is a info message")
logger.warning("this is a warning message")
logger.error("this is a error message")
logger.critical("this is a critical message")
